#include "Render.h"

Render::Render(ALLEGRO_BITMAP *image)
{
    _image = image;
    _face = 1;
}

void Render::drawImage(int pos_x, int pos_y, int direction_x, int direction_y)
{

    if ( direction_x > 0 )
    {
        al_draw_bitmap(_image, pos_x, pos_y, 0);
        _face = 1;
    }

    else if ( direction_x < 0 )
    {
        al_draw_bitmap(_image, pos_x, pos_y, ALLEGRO_FLIP_HORIZONTAL);
        _face = 2;
    }

    else if ( direction_y < 0)
    {
        al_draw_rotated_bitmap(_image, 50, 0, pos_x, pos_y, 3*ALLEGRO_PI/2, 0 );
        _face = 3;
    }

    else if ( direction_y > 0 )
    {
        al_draw_rotated_bitmap(_image, 0, 50, pos_x, pos_y, ALLEGRO_PI/2, 0 );
        _face = 4;
    }

    else if ( direction_x == 0 && direction_y == 0 )
    {
        if ( _face == 1 ) al_draw_bitmap(_image, pos_x, pos_y, 0);
        else if ( _face == 2 ) al_draw_bitmap(_image, pos_x, pos_y, ALLEGRO_FLIP_HORIZONTAL);
        else if ( _face == 3 ) al_draw_rotated_bitmap(_image, 50, 0, pos_x, pos_y, 3*ALLEGRO_PI/2, 0 );
        else if ( _face == 4 ) al_draw_rotated_bitmap(_image, 0, 50, pos_x, pos_y, ALLEGRO_PI/2, 0 );

    }

}

void Render::destroyImage()
{
    if(_image != NULL)
    {
        al_destroy_bitmap(_image);
    }
}

